﻿using System.IO;
using System;
using System.Collections.Generic;
using Jxym.DBUtility;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Jxym.Common.JSON;
using System.Data.SqlClient;
using Jxym.wlkc2011.Module.Default.model;
using Newtonsoft.Json.Converters;

namespace Jxym.wlkc2011.Module.Default.server.Files
{
    public partial class FilesDown : System.Web.UI.Page
    {
        MsSqlDal<model.Files> Bfiles = new MsSqlDal<model.Files>();
        SqlParameter[] values = new SqlParameter[] { };
        model.Files files = new model.Files();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["nodeId"] != null)
                {
                    int id = Convert.ToInt32(Request.Params["nodeId"]);
                    files = Bfiles.GetModel("ID=" + id, values);
                    string path = files.Path;
                    string type = files.Type;
                    if (files != null)
                    {
                        DownLoad(path,type);
                    }
                }
            }
        }
        public void DownLoad(string path,string type)
        {
            string filePath = Server.MapPath("~/UpFiles") + "\\" + type+"\\"+path;
            if (System.IO.File.Exists(filePath))
            {
                FileInfo file = new FileInfo(filePath);
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                Response.AddHeader("Content-length", file.Length.ToString());
                Response.ContentType = "appliction/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
            else
            {
                Label1.Text = "您访问的文件不存在或已删除！";
            }
        }
    }
}